package sk.stuba.fiit.npr.main;

import java.io.File;
import java.io.IOException;
import java.util.Map;

import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;

import sk.stuba.fiit.npr.console.ConsoleManager;
import sk.stuba.fiit.npr.la.LexicalUnitManager;
import sk.stuba.fiit.npr.la.XMLParser;
import sk.stuba.fiit.npr.sa.SA;


public class Launcher {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		XMLParser xmlParser = new XMLParser();
		try {
			xmlParser.startParse(new File(System.getProperty("user.dir") + File.separator + "conf"+ File.separator +"examples.xml"));
			Map<String, String> parsedSimpleURL = xmlParser.getParsedSimpleURL();
			runAnalysis(parsedSimpleURL);
//			LexicalUnitManager.catchLexicalUnits(ConsoleManager.showMenu(parsedSimpleURL));
//			LexicalUnitManager.catchLexicalUnits(ConsoleManager.writeAndSelectParsedLexicalUnits(parsedSimpleURL));
		} catch (ParserConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	private static void runAnalysis(Map<String, String> parsedSimpleURL) {
		LexicalUnitManager.catchLexicalUnits(ConsoleManager.showMenu(parsedSimpleURL));
		SA sa = new SA();
		if(LexicalUnitManager.getValues().size() > 1) {
			sa.process(LexicalUnitManager.getValues());
		} else {
			System.out.println("Vstup nepozostaval len z lexikalnych jednotiek");
		}
//		LexicalUnitManager.getValues();
		if(ConsoleManager.continueWithNextURL()) {
			runAnalysis(parsedSimpleURL);
		}
	}

}

//SA sa = new SA();
//sa.process(vstup);
